package com.luoLight.utils;

import java.io.*;
import java.util.List;

/**
 * 集合相关工具类
 * @author luolight
 * @date 2021-12-8 00:31:13
 * @version 0.1
 */
public class LCollection {

    /**
     * 深拷贝
     * @param src 被拷贝数据
     * @param <T> 被拷贝数据泛型
     * @return
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException {
        //判断src非空
        if(null == src || src.size() == 0) return null;

        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);

        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        @SuppressWarnings("unchecked")
        List<T> dest = (List<T>) in.readObject();
        return dest;
    }



}
